根据中序遍历和前序遍历创建一棵二叉树
思想：就是根据前序，将中序遍历结果分为左子树根右子树这3部分。
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    TreeNode* _buildTree(vector<int>& preorder, vector<int>& inorder,int& pbegin,int ibegin,int iend)
    {
        TreeNode* root=new TreeNode(preorder[pbegin]);
        if(ibegin>iend)
        {
            return nullptr;
        }
        
        int cur=0;
        while(preorder[pbegin]!=inorder[cur])
        {
            cur+=1;
        }
        if(cur!=ibegin)
        {
            root->left=_buildTree(preorder,inorder,++pbegin,ibegin,cur-1);
        }
        else
        {
            root->left=nullptr;
        }
        if(cur!=iend)
        {
            root->right=_buildTree(preorder,inorder,++pbegin,cur+1,iend);
        }
        else
        {
            root->right=nullptr;
        }
        return root;
    }
    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
        if(preorder.size()==0)
        {
            return nullptr;
        }
        int pbegin=0;
        int ibegin=0;
        int iend=inorder.size()-1;
        return _buildTree(preorder,inorder,pbegin,ibegin,iend);
    }
};